package com.kingint.web.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.mbg.bas.entity.BasWorkOrderType;
import com.kingint.mbg.bas.mapper.BasWorkOrderTypeMapper;
import com.kingint.web.util.spring.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

/**
 * 工单类型工具类
 */
@Slf4j
public class WorkTypeUtil {

    /**
     * 查询工单类型id
     * @param name
     * @return
     */
    public static Integer getWorkTypeIdByName(String name) {
        BasWorkOrderTypeMapper typeMapper = SpringContextHolder.getBean(BasWorkOrderTypeMapper.class);
        QueryWrapper<BasWorkOrderType> wrapper = new QueryWrapper<>();
        wrapper.like("name", name);
        BasWorkOrderType type = typeMapper.selectOne(wrapper);
        if (!StringUtils.isEmpty(type)) {
            return type.getId();
        }
        log.error("工单类型还未设置");
        log.info("工单类型还未设置");
        log.debug("工单类型还未设置");
        return null;
    }
}
